package com.example.blogdemo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.fragment.app.Fragment
import com.example.blogdemo.databinding.ActivityMainBinding

/**
 * 基础的list
 */
abstract class BaseListFragment : Fragment() {
    private val arrays = mutableListOf<ClickItem>()
    private lateinit var binding: ActivityMainBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = ActivityMainBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initArray(arrays)
        binding.listMan.setOnItemClickListener { adapterView, view, i, l ->
            arrays[i].click()
        }
        binding.listMan.adapter = ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, arrays)
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)



    }

    abstract fun initArray(arrays: MutableList<ClickItem>)

    override fun onDestroy() {
        super.onDestroy()
        arrays.clear()

    }

}